package com.voxel.sense.infomsg.module.firm.details.device;

import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;

import com.example.com.common.app.BasePresenter;
import com.example.com.common.factory.data.DataSource;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.module.map.warn.FirmWarnPresenter;
import com.voxel.sense.infomsg.utils.GPSUtils;

import java.util.List;

import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.response.FirmDeviceInfoBean;

import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.response.WarningFirmEntity;
import cyy.example.com.facotry.net.helper.FirmNetHelper;

public class FirmDevicePresenter extends BasePresenter<FirmDeviceContaract.View>
  implements FirmDeviceContaract.Presenter, DataSource.Callback<BaseEntity<List<FirmDeviceInfoBean>>>{
  private Handler mHandler;
  private HandlerThread mHandlerThread;

  public FirmDevicePresenter(FirmDeviceContaract.View view) {
    super(view);
  }

  @Override
  public void start() {
    super.start();
    mHandlerThread = new HandlerThread("loadData");
    mHandlerThread.start();
    mHandler = new DataHandle(mHandlerThread.getLooper());
  }

  @Override
  public void onDataNotAvailable(String strRes, int reqId) {

  }

  @Override
  public void doLoadData(String condition) {

  }

  @Override
  public void getDevicesList(String componeId) {
    FirmNetHelper.getDevicesList(componeId,this);
  }

  @Override
  public void onDataLoaded(BaseEntity<List<FirmDeviceInfoBean>> data, int reqId) {

    Message message = new Message();
    message.what = DataHandle.LIST_DEVICES;
    message.obj = data.getData();
    mHandler.sendMessage(message);

  }

  private class DataHandle extends Handler {
    static final int LIST_DEVICES = 0; //加载不同角色marker的icon


    private DataHandle(Looper looper) {
      super(looper);
    }

    @Override
    public void handleMessage(Message msg) {
      super.handleMessage(msg);
      switch (msg.what) {
        case LIST_DEVICES:
          Object objStaff = msg.obj;
          if (objStaff instanceof List) {
            mView.onRefreshData(objStaff);
          }
          break;
      }
    }

  }
}
